package com.estronger.shopmanage.ui.aftermarket.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.estronger.shopmanage.R;
import com.estronger.shopmanage.base.MyApplication;
import com.estronger.shopmanage.manager.NetManager;
import com.estronger.shopmanage.ui.aftermarket.bean.AftermarketItem;

import java.util.ArrayList;
import java.util.List;

public class GoodsAdapater extends RecyclerView.Adapter<GoodsAdapater.GoodHodelr>{


    List<AftermarketItem.OrderItem>datas = new ArrayList<>();

    Context mContext;
    public GoodsAdapater(Context c){
        this.mContext = c;
    }

    public void setDatas(List<AftermarketItem.OrderItem> datas) {
        this.datas = datas;
    }

    @NonNull
    @Override
    public GoodHodelr onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.goods_item,parent,false);
        return new GoodHodelr(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GoodHodelr holder, int position) {
        AftermarketItem.OrderItem orderItem = datas.get(position);
        holder.goods_name.setText(orderItem.getFgoodsname());
        holder.goods_property.setText(orderItem.getFsizedesc());
        holder.goods_count.setText(orderItem.getFcomplaintsqty());
        holder.goods_feature.setText(orderItem.getFclmtypedesc());
        MyApplication.imageLoader.displayImage(NetManager.getDownloadURL()
                        + "?filepath=" + orderItem.getFsimplepicfile(), holder.goods_img,
                MyApplication.options);

    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class GoodHodelr extends RecyclerView.ViewHolder {

        TextView goods_name;
        TextView goods_count;
        TextView goods_property;
        ImageView goods_img;
        TextView goods_feature;
        public GoodHodelr(View itemView) {
            super(itemView);
            goods_name = (TextView) itemView.findViewById(R.id.goods_name);
            goods_count = (TextView) itemView.findViewById(R.id.goods_count);
            goods_property = (TextView) itemView
                    .findViewById(R.id.goods_property);
            goods_img = (ImageView) itemView
                    .findViewById(R.id.goods_item_img);
            goods_feature = (TextView) itemView
                    .findViewById(R.id.goods_feature);
        }
    }
}
